//
//  IntergralRecordModel.m
//  quxiangtao
//
//  Created by xbmios on 2018/9/28.
//  Copyright © 2018年 shanhaijin. All rights reserved.
//

#import "IntergralRecordModel.h"

@implementation IntergralRecordModel

#pragma mark -积分明细
+ (void)integralModelWithType:(NSInteger)type andPage:(NSInteger)page success:(HttpRequestSuccess)successBlock failBlock:(HttpRequestFailed)failBlock {
    
    NSString *pageNum = [RSA encryptString:[NSString stringWithFormat:@"%ld", (long)page] publicKey:PublicKey];
    NSString *rsaType = [RSA encryptString:[NSString stringWithFormat:@"%ld", (long)type] publicKey:PublicKey];
    NSString *userID = [RSA encryptString:[CommonUserInfo sharedInstance].user_id publicKey:PublicKey];
    NSString *number = [RSA encryptString:@"10" publicKey:PublicKey];
    
    NSString *par = [NSString stringWithFormat:@"{\"user_id\" : \"%@\", \"type\" : \"%@\", \"page\" : \"%@\", \"number\" : \"%@\"}", userID, rsaType, pageNum, number];
    
    [PPNetworkHelper POST:@"user/Bean/llbdetail" parameters:@{@"json" : par} success:^(id responseObject) {
        
        NSLog(@"积分明细：%@",responseObject);
        
        NSArray *dictArr = responseObject[@"data"];
        
        NSMutableDictionary *d = [NSMutableDictionary dictionaryWithDictionary:responseObject];
        
        if (dictArr.count > 0) {
            
            // 转模型数组
            NSArray *modelArr = [IntergralRecordModel mj_objectArrayWithKeyValuesArray:dictArr];
            
            [d removeObjectForKey:@"data"];
            [d setObject:modelArr forKey:@"data"];
        }
        
        if (successBlock) {
            
            successBlock(d);
            
        }
        
    } failure:^(NSError *error) {
        
        if (failBlock) {
            
            failBlock(error);
            
        }
        
    }];
    
}


#pragma mark -积分兑换记录
+ (void)integralRecordListWithPage:(NSInteger)page successBlock:(HttpRequestSuccess)successBlock failBlock:(HttpRequestFailed)failBlock {
    
    NSString *str = [NSString stringWithFormat:@"{\"user_id\" : \"%@\", \"page\" : \"%@\", \"number\" : \"%@\"}", [RSA encryptString:[CommonUserInfo sharedInstance].user_id publicKey:PublicKey], [RSA encryptString:[NSString stringWithFormat:@"%zd", page] publicKey:PublicKey], [RSA encryptString:@"10" publicKey:PublicKey]];
    
    [PPNetworkHelper POST:@"user/Welfare/Beanexchangerecord" parameters:@{@"json" : str} success:^(id responseObject) {
        
        NSLog(@"积分兑换记录:%@", responseObject);
        
        NSArray *dictArr = responseObject[@"data"];
        
        NSMutableDictionary *d = [NSMutableDictionary dictionaryWithDictionary:responseObject];
        
        if (dictArr.count > 0) {
            
            // 转模型数组
            NSArray *modelArr = [IntergralRecordModel mj_objectArrayWithKeyValuesArray:dictArr];
            
            [d removeObjectForKey:@"data"];
            [d setObject:modelArr forKey:@"data"];
        }
        
        if (successBlock) {
            
            successBlock(d);
            
        }
        
    } failure:^(NSError *error) {
        
        if (failBlock) {
            
            failBlock(error);
        }
        
        
    }];
    
}


@end
